package com.ctriposs.baiji.rpc.samples.movie;

import com.ctriposs.baiji.rpc.client.ServiceClientConfig;

/**
 * Created by yqdong on 2014/9/8.
 */
public class Client {

    public static void main(String[] args) throws Exception {
        try {
            ServiceClientConfig config = new ServiceClientConfig();
            config.setAppId("921999");
            config.setFxConfigServiceUrl("http://ws.config.framework.fws.qa.nt.ctripcorp.com/Configws/");
            config.setSubEnv("dev");
//          config.setServiceSubEnv(MovieServiceClient.ORIGINAL_SERVICE_NAME, MovieServiceClient.ORIGINAL_SERVICE_NAMESPACE, "dev");
            MovieServiceClient.initialize(config);

//          MovieServiceClient client = MovieServiceClient.getInstance("http://localhost:8080/");
            MovieServiceClient client = MovieServiceClient.getInstance();
            GetMoviesRequestType request = new GetMoviesRequestType(5);
            GetMoviesResponseType response = client.getMovies(request);
            if (response.movies == null || response.movies.isEmpty()) {
                System.out.println("No movie found.");
            } else {
                for (MovieDto movie : response.movies) {
                    System.out.println(String.format("#%s %s", movie.id, movie.title));
                }
            }
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            System.exit(0);
        }
    }
}
